(function($){
    var _defaultConfig = {
        keyWidth : 30,
        converter : []
    };
    
    $.fn.jsonViewer = function(json, config) {
        var $this = $(this).first().addClass('json-viewer');
        var jsonKeyItemTmp = [
            '<dl>',
                '<dt style="width:{keyWidth}px">{key}:</dt>',
                '<dd style="margin-left:{keyWidth}px">{val}</dd>',
            '</dl>'
        ].join('');
        config = $.extend({}, _defaultConfig, config);
        
        if(!(json instanceof Array)){
            json = [ json ];
        }
        
        $.each(json, function(index, jsonItem){
            var $jsonItem = $('<div class="jsonItem {jsonItemOrderType}"></div>'.format({
                jsonItemOrderType : index % 2 ? '' : 'odd'
            }));
            $.each(jsonItem, function(key, val){
                var valConverter = config['converter'][key]; 
                $jsonItem.append(jsonKeyItemTmp.format({
                    key : key,
                    val : valConverter ? valConverter(val) : val + '',
                    keyWidth : config['keyWidth']
                }));
            });
            $this.append($jsonItem);
        });  
    };    
})(jQuery);